<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        div {
            display: none;
            width: 100px;
            height: 100px;
            background-color: #6ff;
            position: fixed;
            right: 20px;
            bottom: 40px;
        }

        .active {
            display: block;
        }

        body {
            height: 6000px;
        }
    </style>
</head>

<body>
    <div class="xf"></div>
</body>
<script>
    var xf = document.getElementsByClassName("xf")[0];
    window.onscroll = (function () {
        var lasttime = 0;
        return function () {
            var now = new Date().getTime(); //每次触发事件获取当前时间
            if (now - lasttime > 200) { //若时间间隔大于了200ms
                lasttime = now;  //执行代码，并重新计时
                var toTop = document.documentElement.scrollTop;
                console.log(toTop);
                xf.setAttribute("class", "active");
            }
        }
    })()
</script>

</html>